package com.ruoyi.carton.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.carton.domain.Cardboard;
import com.ruoyi.carton.domain.vo.CardboardVO;
import com.ruoyi.carton.mapper.CardboardMapper;
import com.ruoyi.carton.service.CardboardService;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
* @author 时空
* @description 针对表【cardboard(纸板信息表)】的数据库操作Service实现
* @createDate 2025-06-28 13:26:36
*/
@Service
public class CardboardServiceImpl extends ServiceImpl<CardboardMapper, Cardboard>
    implements CardboardService{

    @Override
    public boolean addCardboard(CardboardVO cardboardVo) {
        String cardboardId = UUID.randomUUID().toString().replace("-", "");
        Cardboard cardboard = new Cardboard();
        cardboard.setId(cardboardId);
        cardboard.setFluteType(cardboardVo.getFluteType());
        cardboard.setLayerCount(cardboardVo.getLayerCount());
        cardboard.setMaterialCode(cardboardVo.getMaterialCode());
        cardboard.setSizeLength(cardboardVo.getSizeLength());
        cardboard.setSizeWidth(cardboardVo.getSizeWidth());
        cardboard.setScoringLine(cardboardVo.getScoringLine());
        cardboard.setMaterialDesc(cardboardVo.getMaterialDesc());
        cardboard.setCrushStrength(cardboardVo.getCrushStrength());
        cardboard.setEdgeCrush(cardboardVo.getEdgeCrush());
        cardboard.setBurstStrength(cardboardVo.getBurstStrength());
        cardboard.setUnitPrice(cardboardVo.getUnitPrice());

        // 关键：调用数据库保存方法
        return this.save(cardboard);
    }

    @Override
    public List<Cardboard> selectCardboardList(Cardboard cardboard) {
        return this.lambdaQuery()
                .eq(StringUtils.isNotBlank(cardboard.getFluteType()), Cardboard::getFluteType, cardboard.getFluteType())
                .eq(cardboard.getLayerCount() != null, Cardboard::getLayerCount, cardboard.getLayerCount())
                .like(StringUtils.isNotBlank(cardboard.getMaterialCode()), Cardboard::getMaterialCode, cardboard.getMaterialCode())
                .list();
    }

}




